//
//  SetupViewController.m
//  ICrEAM
//
//  Created by mac on 16/11/25.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "SetupViewController.h"
#import "LoginViewController.h"
#import "AppDelegate.h"
#import "CofigViewController.h"
@interface SetupViewController ()
@property (weak, nonatomic) IBOutlet UILabel *versionL;
@property (weak, nonatomic) IBOutlet UILabel *mobieFirstL;
@property (weak, nonatomic) IBOutlet UILabel *mobileSecodeL;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@end

@implementation SetupViewController
- (IBAction)loginOut:(id)sender {
    [[ICreamCache sharedInstance] removeDataForKey:HomePagePath];
    LoginViewController *login=[[LoginViewController alloc]init];
    login.hideNav=YES;
    login.hideRightNavItem=YES;
    login.hideSuspendView=YES;
    [AppDelegate currentAppDelegate].window.rootViewController= login;
}
- (IBAction)outConfig:(id)sender {
    
    CofigViewController *config=[[CofigViewController alloc]init];
    config.hideNav=YES;
    config.hideRightNavItem=YES;
    config.hideSuspendView=YES;
    config.ipText=[[ICreamCache sharedInstance] stringForKey:kIPPath];
    [[ICreamCache sharedInstance] removeDataForKey:kIPPath];
    [[ICreamCache sharedInstance] removeDataForKey:isVWPath];
    [[ICreamCache sharedInstance] removeDataForKey:HomePagePath];
    [[ICreamCache sharedInstance] removeDataForKey:kHotLine];
    
    [AppDelegate currentAppDelegate].window.rootViewController= [[UINavigationController alloc]initWithRootViewController:config];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
//    if (self.isTop) {
//        self.topConstraint.constant=64;
//    }else{
//        self.topConstraint.constant=ScreenHeight-300;
//    }
    if (![ICrEAMTool isVW]) {
        self.titleLabel.textColor=KSKBgColor;
    }
    
    NSArray *hotlines=[[ICreamCache sharedInstance] arrayForKey:kHotLine];
    if (!IsArrEmpty(hotlines)) {
        self.mobieFirstL.text=hotlines[0];
        if(hotlines.count==2){
//            self.mobileSecodeL.text=hotlines[1];
        }
    }
//    NSString * key=@"CFBundleVersion";
//    NSString *  currentVersion= [NSBundle mainBundle].infoDictionary[key];
//    self.versionL.text=currentVersion;
    self.bgView.layer.cornerRadius=4;
    self.bgView.layer.masksToBounds=YES;
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    // 当前应用名称
    NSString *appCurName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    NSLog(@"当前应用名称：%@",appCurName);
    // 当前应用软件版本  比如：1.0.1
    NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSLog(@"当前应用软件版本:%@",appCurVersion);
    // 当前应用版本号码   int类型
    NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];
    NSLog(@"当前应用版本号码：%@",appCurVersionNum);
    self.versionL.text = appCurVersion;
    
    
    
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)showOnView:(UIWindow *)window
{
    CGRect frame = [UIScreen mainScreen].bounds;
    
    //    CGFloat height=with*
    //        self.view.frame = CGRectMake(ScreenWidth-600, 200, 550, 450);
    self.view.frame=frame;
    [window addSubview:self.view];
    if (!IOS7_OR_LATER) {
        frame.origin.y = 20;
        frame.size.height-=20;
    }
    
}
- (void)setDismissBlock:(ICrEAMBlock)block
{
    if (block != dismissBlock) {
        dismissBlock = [block copy];
    }
}
//移除页面
- (void)removeAdImageView
{
    [UIView animateWithDuration:3.0f animations:^{
        self.bgView.alpha = 0.999f;
    } completion:^(BOOL finished) {
        [self.bgView removeFromSuperview];
        
        [self.view removeFromSuperview];
        if (dismissBlock) {
            dismissBlock();
        }
    }];
    
}
- (void)animationFinished{
    [self removeAdImageView];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    self.view.backgroundColor=[UIColor clearColor];
    CGContextRef contentext = UIGraphicsGetCurrentContext();
    
    [UIView beginAnimations:nil context:contentext];
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
    [UIView setAnimationDuration:0.7];
    
    self.view.transform = CGAffineTransformMakeTranslation(self.view.width, 0);
    
    [UIView setAnimationDelegate:self];
    
    [UIView setAnimationDidStopSelector:@selector(animationFinished) ];
    
    [UIView commitAnimations];
}

@end
